<template>

  <div class="content">
    <nav-title title="欢迎您加入奥克斯" :notback="false"/>
    <div class="login-box">
      <button @click="setCookie">设置cookie</button>
      <button @click="setCookie2">设置cookie2</button>
      <button @click="clearCookie">清除cookie</button>
      <button @click="getCookie">获取cookie</button>
    </div>
  </div>
</template>

<script>

  export default {
    name: "information-login",
    data() {
      return {
        nationalId:'',
        name:''
      }
    },

    methods: {
      setCookie() {
            alert("setCookie");
          var Days = 30;
          var exp = new Date();
          exp.setTime(exp.getTime() + Days*24*60*60*30);
          document.cookie = "wechat-token="+ escape ('99558saxs') + ";expires=" + exp.toGMTString() + "; path=/;";
      },
      setCookie2() {
          alert("setCookie");
          var Days = 30;
          var exp = new Date();
          exp.setTime(exp.getTime() + Days*24*60*60*30);
          document.cookie = "wechat-token="+ escape ('222229955822saxs') + ";expires=" + exp.toGMTString() + "; path=/;domain=auxgroup.com;";
      },
      clearCookie() {
        alert("clear");
        let date=new Date();
          date.setTime(date.getTime()-1000000);
          let keys=document.cookie.match(/[^ =;]+(?=\=)/g);
          console.log(keys);
          if (keys) {
            for (let i = keys.length; i--;) {
              document.cookie=keys[i]+"=; expire="+date.toGMTString()+"; path=/";
            }
          }
      },
      getCookie() {

        var c_name = 'wechat-token'
        var c_start;
        var c_end;
        if (document.cookie.length > 0) {
            var arr = document.cookie.split(/;\s*/g);
            console.log(arr);
            for(var i = 0; i < arr.length; i++){
              var arr2=arr[i].split('=');
              if(c_name==arr2[0].trim()){ 
                  if(arr2[1].trim().length > 10){
                    alert(arr2[1]);
                    return unescape(arr2[1]);
                  }
              } 
            }
        }
        return undefined;
      }
    }
  }
</script>


